home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MacTextFieldUI.java < prev    next >
Text File  |  1998-06-30  |  5KB  |  178 lines

  1. /*
  2.  * @(#)MacTextFieldUI.java    1.6 98/02/02
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21.  
  22. package com.sun.java.swing.plaf.mac;
  23.  
  24. import java.awt.*;
  25. import java.awt.event.*;
  26. import com.sun.java.swing.*;
  27. import com.sun.java.swing.plaf.basic.BasicTextFieldUI;
  28. import com.sun.java.swing.border.*;
  29. import com.sun.java.swing.event.*;
  30. import com.sun.java.swing.text.*;
  31. import com.sun.java.swing.plaf.*;
  32.  
  33. /**
  34.  * Provides the Mac look and feel for a text field.
  35.  * <p>
  36.  * Warning: serialized objects of this class will not be compatible with
  37.  * future swing releases.  The current serialization support is appropriate
  38.  * for short term storage or RMI between Swing1.0 applications.  It will
  39.  * not be possible to load serialized Swing1.0 objects with future releases
  40.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  41.  * baseline for the serialized form of Swing objects.
  42.  *
  43.  * @version @(#)MacTextFieldUI.java    1.0 11/24/97
  44.  * @author Symantec
  45.  */
  46. public class MacTextFieldUI extends MacTextUI {
  47.  
  48.     /**
  49.      * Creates a UI for a JTextField.
  50.      *
  51.      * @param c the text field
  52.      * @return the UI
  53.      */
  54.     public static ComponentUI createUI(JComponent c) {
  55.         return new MacTextFieldUI();
  56.     }
  57.  
  58.     /**
  59.      * Name used as a key to lookup properties through the
  60.      * UIManager.  This is used as a prefix to all the standard
  61.      * text properties.
  62.      */
  63.     protected String getPropertyPrefix() {
  64.     return "TextField";
  65.     }
  66.  
  67.     /**
  68.      * Creates a view based on an element.
  69.      *
  70.      * @param elem the element
  71.      * @return the view
  72.      */
  73.     public View create(Element elem) {
  74.     return new FieldView(elem);
  75.     }
  76.  
  77.     /**
  78.      * Creates a view based on an element.
  79.      *
  80.      * @param elem the element
  81.      * @param p0 the starting offset
  82.      * @param p1 the ending offset
  83.      * @return the view
  84.      */
  85.     public View create(Element elem, int p0, int p1) {
  86.     throw new Error("unsupported");
  87.     }
  88.  
  89.     /**
  90.      * Creates the object to use for a caret.  By default an
  91.      * instance of MacTextUI.MacCaret is created.  This method
  92.      * can be redefined to provide something else that implements
  93.      * the Caret interface.
  94.      *
  95.      * @return the caret object
  96.      */
  97.     protected Caret createCaret() {
  98.     return new MacFieldCaret();
  99.     }
  100.  
  101.     /**
  102.      * Load the given keymap with default settings
  103.      * appropriate for the UI being created.  This
  104.      * is implemented to do the superclass behavior 
  105.      * as well as load the settings appropriate for
  106.      * a single-line text editor.
  107.      */
  108.     protected void loadDefaultKeymap(Keymap map) {
  109.     super.loadDefaultKeymap(map);
  110.     JTextComponent.loadKeymap(map, fieldBindings, 
  111.                      getComponent().getActions());
  112.     }
  113.  
  114.     /**
  115.      * Paints the background of the field.
  116.      *
  117.      * @param g the graphics context
  118.      */
  119.  /*   protected void paintBackground(Graphics g) {
  120.     JTextField field = (JTextField) getComponent();
  121.     if(field.isOpaque()) {
  122.         g.setColor(field.getBackground());
  123.         Dimension d = field.getSize();
  124.         g.fillRect(-field.getScrollOffset(), 0, d.width, d.height);
  125.     }
  126.     }
  127. */
  128.     /**
  129.      * Default bindings multi-line editor keymaps implementing the Mac feel.
  130.      */
  131.     static final JTextComponent.KeyBinding[] fieldBindings = {
  132.     new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
  133.                        JTextField.notifyAction)
  134.     };
  135.  
  136.     /**
  137.      * <p>
  138.      * Warning: serialized objects of this class will not be compatible with
  139.      * future swing releases.  The current serialization support is appropriate
  140.      * for short term storage or RMI between Swing1.0 applications.  It will
  141.      * not be possible to load serialized Swing1.0 objects with future releases
  142.      * of Swing.  The JDK1.2 release of Swing will be the compatibility
  143.      * baseline for the serialized form of Swing objects.
  144.      */
  145.     public class MacFieldCaret extends MacTextUI.MacCaret {
  146.  
  147.         /**
  148.          * Creates a new controller to serve an editor.
  149.          *
  150.          * @param editor the text editor
  151.          */
  152.         public MacFieldCaret() 
  153.         {
  154.             super();
  155.         }
  156.     
  157.         /**
  158.          * Repaint the entire component to paint the focus rectangle
  159.          */
  160.                 public void focusGained(FocusEvent e)
  161.         {
  162.             super.focusGained(e);
  163.             getComponent().repaint();
  164.         }
  165.     
  166.             /**
  167.          * Repaint the entire component to paint the focus rectangle
  168.          */
  169.                 public void focusLost(FocusEvent e)
  170.         {
  171.                 super.focusLost(e);
  172.             getComponent().repaint();
  173.             
  174.         }
  175.     }
  176.  
  177. }
  178.